package com.example.demo1.response;

import com.example.demo1.exception.ExceptionEnum;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ApiModel
public class Response {

    @ApiModelProperty("响应码")
    private Integer code;

    @ApiModelProperty("响应信息")
    private String msg;

    @ApiModelProperty("响应数据")
    private Object data;

    public Response(Integer code, String msg) {
        this.msg = msg;
        this.code = code;
    }

    public static Response success(Object data) {
        return new Response(200, "请求成功", data);
    }

    public static Response success() {
        return new Response(200, "请求成功", null);
    }

    public static Response error(ExceptionEnum ex) {
        return new Response(ex.getCode(), ex.getMsg(), null);
    }

    public static Response error(Integer code2, String message) {
        return new Response(code2, message, null);
    }

}
